"""主路由模块"""
from flask import Blueprint, render_template, session, make_response
from app.utils.decorators import login_required
from app.models.system_update import SystemUpdate

bp = Blueprint('main', __name__)

@bp.route('/')
@login_required
def index():
    """首页"""
    # 获取最新的系统版本信息
    latest_version = SystemUpdate.get_latest_version()
    return render_template('index.html', username=session['username'], system_version=latest_version['version'])

@bp.route('/static/js/<path:filename>.map')
def handle_js_sourcemap(filename):
    """处理JS source map文件请求（返回空响应，避免404日志）"""
    response = make_response('', 204)
    response.headers['Content-Type'] = 'application/json'
    return response

@bp.route('/static/css/<path:filename>.map')
def handle_css_sourcemap(filename):
    """处理CSS source map文件请求（返回空响应，避免404日志）"""
    response = make_response('', 204)
    response.headers['Content-Type'] = 'application/json'
    return response

